<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");

$errMsg = "";
if(sxREQUEST("reqtype") == "save"){
	$errMsg .= domainValueMod();	
}
if(sxREQ("dom")!='') {
	$sSQL = "SELECT * FROM domain_value " .
			" WHERE domain='".sxREQ("dom")."' AND value = '".sxREQ("val")."'";
	$objSDAO->query($sSQL, "val");
	$row = $objSDAO->fetch('val');
	$_REQUEST['domain'] = $row['domain'];
	$_REQUEST['value'] = $row['value'];
	$_REQUEST['description'] = $row['description'];
	$_REQUEST['note'] = $row['note'];
	$_REQUEST['sequence'] = $row['sequence'];
}
//leggo i valori gi@ inseriti
$aOpz = array("kMenu"=>'dam.dom', "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script>  
<script language="JavaScript" type="text/javascript">
</script>
  
<?php
echo(bodyHTML($aOpz));
//output comandi
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
//form inserimento dati
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" id=\"xsn\" value=\"".XSN."\">");

$aCmd = array("insRel"=>array("pag"=>"javascript:document.objFrm.submit()",
										"title"=>_t("save"),
										"text"=>_t("save"),
										"perm"=>"newdom"),
					"back"=>array("pag"=>$objUser->getHistory(0, false),
										"title"=>"cancel",
										"text"=>"cancel")
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"labl01\" width=\"25%\">"._t("Domain")."</td>" .
		"<td class=\"text01\" width=\"75%\">" .sxREQUEST('domain').
		"<input class=\"inpt01\" type=\"hidden\" name=\"domain\" id=\"domain\" value=\"".sxREQUEST('domain')."\"></td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"titl01\" colspan=\"2\">"._t("Domain value")."</td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("Value")." (*)</td>" .
		"<td class=\"text01\">" .sxHE(sxREQUEST('value')).
		"<input type=\"hidden\" name=\"value\" id=\"value\" value=\"".sxHE(sxREQUEST('value'))."\" ></td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("Description")." (*)</td>" .
		"<td class=\"text01\">" .
		"<input class=\"inpt01\" type=\"text\" name=\"description\" id=\"description\" value=\"".sxHE(sxREQUEST('description'))."\" maxlength=\"80\" size=\"60\"></td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("Sequence")." (*)</td>" .
		"<td class=\"text01\">" .
		"<input class=\"inpt01\" type=\"text\" name=\"sequence\" id=\"sequence\" value=\"".sxHE(sxREQUEST('sequence'))."\" size=\"20\"></td>" .
	"</tr>\n");
echo("<tr>" .
	"<td class=\"labl01\">"._t("Note")."</td>" .
	"<td class=\"text01\">" .
	"<textarea class=\"inpt01\" name=\"note\" id=\"note\" cols=\"80\" rows=\"5\">".sxHE(sxREQUEST('note'))."</textarea></td>" .
"</tr>\n");

echo(commandsHTML($aCmd));
echo("</form>\n");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());

function domainValueMod(){
	global $objSDAO, $objUser;
	$errMsg = "";
	if(sxREQUEST("description") == "")
		$errMsg .= _t("La description &egrave; obbligatoria")."<br>";
	if(ereg("[^0-9]",sxREQUEST("sequence")))
		$errMsg .= _t("La sequenza deve essere un numerico")."<br>";
	if($errMsg != "")
		return $errMsg;
	$sSQL = "UPDATE domain_value SET " .
			" description = '".sxRAS("description")."', " .
			" sequence = ".sxRAS("sequence").", " .
			" note = '".sxRAS("note")."'" .
			" WHERE domain = '".sxRAS("domain")."' AND value = '".sxRAS("value")."'";
	$objSDAO->exec($sSQL);
	serverRedir($objUser->getHistory(0));
	return '???';
}
